//STL(1-4)案例_ 评委打分
//五名选手，ABCDE， 10个评委打分，去除最高分和最低分，取平均分
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<string>
#include<ctime>

using namespace std;


class Person
{
public:
	Person(string name, int score)
	{
		this->m_Name = name;
		this->m_Score = score;
	}


	string m_Name;
	int m_Score;
};

void creatPerson(vector<Person>& v)
{
	string nameSeed = "ABCDE";
	for (int i = 0; i < 5; i++)
	{
		string name = "选手";
		name += nameSeed[i];

		int score = 0;
		Person p(name, score);

		//放入vector中
		v.push_back(p);
	}
}

void setScore(vector<Person>& v)
{
	for (vector<Person>::iterator it = v.begin(); it != v.end(); it++)
	{
		//将评委分数放入deque中
		deque<int> d;
		for (int i = 0; i < 10; i++)
		{
			//60-100随机数
			int score = rand() % 41 + 60;
			d.push_back(score);
		}
		
		cout << "选手：" << it->m_Name <<  "\t打分：" << endl;
		for (deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
		{ 
			cout << *dit << "  ";
		}
		cout << endl;

		//排序
		sort(d.begin(), d.end());

		//去除最高和最低
		d.pop_back();
		d.pop_front();

		//算平均分
		int sum = 0;
		for (deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
		{
			sum += *dit;
		}

		int avg = sum / (int)d.size();

		//将分数给到选手
		it->m_Score = avg;
	}
}

void showScore(vector<Person>& v)
{
	for (vector<Person>::iterator it = v.begin(); it != v.end(); it++)
	{
		cout << "姓名：" << it->m_Name << "\t分数：" << it->m_Score << endl;
	}
}

int main()
{
	//随机数种子
	srand((unsigned int)time(NULL));

	//1.创建5名选手
	vector<Person> v;
	creatPerson(v);
	
	//2.打分
	setScore(v);

	//3.显示得分
	cout << endl;
	showScore(v);
	return 0;
}

